<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>java189后台管理系统</title>
	<base href="<%=basePath%>">
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="css/icon.css">
     <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/mobile.css">
	<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
	/* 参数传递,用于打开tabs */
	function addTabs(title,url,id){
		if($("#tt").tabs("exists",title)){
			$("#tt").tabs("select",title);
		}else{
			$('#tt').tabs('add',{    
			    title:title,    
			   // href:url, 
			    closable:true,
			    content:"<iframe scrolling='yes' frameborder='0'  src='"+url+"?menu_id_user="+id+"' style='width:100%;height:100%;overflow:auto;fit:true'></iframe>"
			});  
		}
	  }
	</script>
</head>

<body class="easyui-layout">
  <div id="cc" class="easyui-layout" style="width:100%;height:95%;">   
    <div data-options="region:'north',border:false" style="height:100px;background-image:url('images/logo.png');background-repeat: no-repeat;">
    	<!-- <img alt="logo" src="images/logo.png" style="padding: 20px 0 0 20px;"> -->
    	<div align="center" style="margin-top: 10px;"><h3>您好,${sessionScope.StaffAccount},欢迎登陆!</h3></div>
    	<div style="float:right;margin-top: -40px;">
    		<h3><a href="javascript:void(0)" id="change" style="text-decoration: none;font-size: 16px;color: #52afb7">修改密码</a>|<a href="admin/loginOut.do" style="text-decoration: none;font-size: 16px;color: #a5cf4c">退出系统</a></h3>
    	</div>
    </div> 
    	
    <div data-options="region:'west',title:'导航菜单',split:true" style="width:200px;">
    	<div id="aa" class="easyui-accordion" data-options="fit:true,border:false">   
    		<ul id='tree'></ul>
    		  
		</div> 
    </div>  
     
    <div data-options="region:'center',border:false,plain:true">
		<div id="tt" class="easyui-tabs" fit=true style="">   
		    <div title="首页" style="text-align:left;font-size: 16px;">  
		    	<div>
		    	<ul style="list-style:none;color: red">
		    		
		    		<li>本系统采用spring+springmvc+mybatis+easyui</li>
		    		<li>1.本系统实现了对用户权限的控制，将用户权限控制到按钮</li>
		    		<li>2.本系统实现POI导出功能，导入功能并未完善。</li>
		    		<li>3.本系统富文本编辑框使用的是百度UEditor</li>
		    		<li>4.系统的alert框并未使用easyui的警告框，使用的是由贤心开发的layer插件</li>
		    		<li>5.此系统没有其他新颖。很渣的一个系统。</li>
		    	</ul>
		    	</div> 
		         
		    </div>   
		</div>
    	
   </div>   
</div>  
<div style="height: 100px;text-align: center;font-size: 12px;">
	<p>孤独的程序猿&copy;CopyRight</p>
</div>
 <div id="pwddlg" class="easyui-dialog" data-options="iconCls:'icon-edit',resizable:true,modal:true,closed:true" style="width: 400px;height: 300px; padding: 10px 20px" 
           buttons="#pwd-dlg-buttons" >
      <div align="center">
        <form id="pwdfm" class="easyui-form" data-options="novalidate:true">
        	<table>
        		<tr>
        			<td><label>原密码:</label></td>
        			<td><input class="easyui-textbox"  type="password" required="true" id="password"></td>
        		</tr>
        		<tr>
        			<td><label>新密码:</label></td>
        			<td><input class="easyui-textbox"  type="password"  required="true" id="newPass"></td>
        		</tr>
        		<tr>
        			<td><label>重复新密码:</label></td>
        			<td><input class="easyui-textbox"  type="password"  required="true" id="renewPass"></td>
        		</tr>
        	</table>
        </form>
      </div>
      <div id="pwd-dlg-buttons">
    	<label id="saveUrl" closed="true"></label>
        <a href="javascript:void(0)" id="save" class="easyui-linkbutton c6" iconCls="icon-ok" style="width:90px">保存</a>
        <a href="javascript:void(0)" id="cancel" class="easyui-linkbutton" iconCls="icon-cancel" style="width:90px">取消</a>
    </div>
    </div>
    
</body>
<script type="text/javascript">
	$(function(){
		$('#tree').tree({
        	url: 'admin/queryMenuByStaffId.do?staffId=${sessionScope.AccountId}',
        	animate:true,
        	//lines:true,
        	loadFilter: function(data){
        		return convert(data);
        	},
        	onSelect:function(node){
        		if(node.attributes!=null){
        		addTabs(node.text,node.attributes,node.id);
        		}
        	},
        });

	});
	function convert(data){
    	function exists(data, parentId,menuLevel){
    		
    			for(var i=0; i<data.rows.length; i++){
        			if (data.rows[i].menuId == parentId) 
        				return true;
        			}
    		return false;
    	}
    	
    	var nodes = [];
    	// get the top level nodes
    	for(var i=0; i<data.rows.length; i++){
    		var row = data.rows[i];
    		if (!exists(data, row.parentId,row.menuLevel)){
    			
    				nodes.push({
        				id:row.menuId,
        				text:row.menuName,
        				iconCls:row.iconCls,
        				state:'closed',
        			});
    		}
    	}
    	
    	var toDo = [];
    	for(var i=0; i<nodes.length; i++){
    		toDo.push(nodes[i]);
    	}
    	while(toDo.length){
    		var node = toDo.shift();	// the parent node
    		// get the children nodes
    		for(var i=0; i<data.rows.length; i++){
    			var row = data.rows[i];
    			if (row.parentId == node.id){
    				if(row.onSelect==row.menuId){
    					var child = {
        						id:row.menuId,
        						text:row.menuName,
        						iconCls:row.iconCls,
        						attributes:row.menuUrl,
        						menuLevel:row.menuLevel,
        						};
    					if (node.children){
        					node.children.push(child);
        				} else {
        					node.children = [child];
        				}
        				
    				}else{
    					var child = {
        						id:row.menuId,
        						text:row.menuName,
        						iconCls:row.iconCls,
        						attributes:row.menuUrl
        						};
    					if (node.children){
        					node.children.push(child);
        				} else {
        					node.children = [child];
        				}
    				}
        				toDo.push(child);
    			}
    		}
    	}
    	return nodes;
    }
		$("#change").click(function(){
			$('#pwdfm').form('clear');
			$('#pwddlg').dialog('open').dialog("setTitle","修改密码");
			$("#saveUrl").val('admin/updateStaffPwd.do');
		});
		$("#save").bind("click",function(){
			$.ajax({
				url : $("#saveUrl").val(),
				type : "POST",
				dataType : "json",
				data:{
					'AccountId':'${sessionScope.AccountId}',
					'password':$("#password").textbox('getValue'),
					'newPass':$("#newPass").textbox('getValue'),
					'renewPass':$("#renewPass").textbox('getValue')
				},
				success : function(result) {
					if (result.result == 1) {
						layer.msg(result.tips+",即将跳转登录页面");
						$('#pwddlg').dialog('close');
						window.setTimeout("window.location.href='admin/loginOut.do'",3000); 
					} else {
						layer.msg(result.tips);
					}
				}
		});
		});
		$("#cancel").click(function(){
			$('#pwddlg').dialog('close');
			$('#pwdfm').form('clear');
		});
</script>
</html>